package mapreduce.flowcount.task2;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class FlowBean implements WritableComparable<FlowBean> {
    //上行数据包总和
    private Integer upPackCount;
    //下行数据包总和
    private Integer downPackCount;
    //上行流量总和
    private Integer upFlowCount;
    //下行流量总和
    private Integer downFlowCount;

    /*
    定义排序规则：倒序排列
    每次比较都是调用该方法的对象与传递的参数进行比较
     */
    public int compareTo(FlowBean o) {
        return o.getUpFlowCount() - this.upFlowCount;
    }

    /*
        序列化
         */
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(upPackCount);
        dataOutput.writeInt(downPackCount);
        dataOutput.writeInt(upFlowCount);
        dataOutput.writeInt(downFlowCount);
    }
    /*
    反序列化
     */
    public void readFields(DataInput dataInput) throws IOException {
        this.upPackCount = dataInput.readInt();
        this.downPackCount = dataInput.readInt();
        this.upFlowCount = dataInput.readInt();
        this.downFlowCount = dataInput.readInt();
    }

    public FlowBean() {}
    public FlowBean(Integer upPackCount, Integer downPackCount, Integer upFlowCount, Integer downFlowCount) {
        this.upPackCount = upPackCount;
        this.downPackCount = downPackCount;
        this.upFlowCount = upFlowCount;
        this.downFlowCount = downFlowCount;
    }

    public Integer getUpPackCount() {
        return upPackCount;
    }

    public void setUpPackCount(Integer upPackCount) {
        this.upPackCount = upPackCount;
    }

    public Integer getDownPackCount() {
        return downPackCount;
    }

    public void setDownPackCount(Integer downPackCount) {
        this.downPackCount = downPackCount;
    }

    public Integer getUpFlowCount() {
        return upFlowCount;
    }

    public void setUpFlowCount(Integer upFlowCount) {
        this.upFlowCount = upFlowCount;
    }

    public Integer getDownFlowCount() {
        return downFlowCount;
    }

    public void setDownFlowCount(Integer downFlowCount) {
        this.downFlowCount = downFlowCount;
    }

    @Override
    public String toString() {
        return "FlowBean{" +
                "upPackCount=" + upPackCount +
                ", downPackCount=" + downPackCount +
                ", upFlowCount=" + upFlowCount +
                ", downFlowCount=" + downFlowCount +
                '}';
    }
}
